<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>功能演示二 - 上传组件</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>组件</cite></a>
        <a><cite>上传组件</cite></a>
        <a><cite>功能演示二</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">下载模板</div>
                <div class="layui-card-body">
                    1.下载导入模板并填写内 >> <a href="/excel/题目模板.xlsx" style="color: #01AAED">下载模板</a>
                </div>
            </div>
        </div>

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">导入模板</div>
                <div class="layui-card-body">
                    <div class="layui-upload-drag" id="test-upload-drag">
                        <i class="layui-icon"></i>
                        <p>点击上传，或将文件拖拽到此处</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'upload','layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,layer = layui.layer;
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

        //拖拽上传
        upload.render({
            elem: '#test-upload-drag'
            ,url: '/admin/question/upload'
            ,method: 'post'
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            ,done: function(res){
                layer.closeAll('loading'); //关闭loading
                if(res.code == 0){
                    //刷新表格，关闭窗口
                    parent.layui.table.reload('table-question'); //重载表格
                    parent.layer.close(index); //再执行关闭
                    parent.layer.alert("导入成功");
                }else{
                    layer.msg(res.msg);
                }
            }
            ,error: function(index, upload){
                layer.closeAll('loading'); //关闭loading
            }
            ,accept: 'file'
        });


    });
</script>
</body>
</html>